/**
 * Copyright (c) 2016 Lenovo Group
 * All Rights Reserved.
 * 
 * Project Name:app-gateway
 * Create Time: 2016年1月21日 下午3:33:32
 */
package com.lenovo.lmrp.server.appgateway.util;

import com.lenovo.lmrp.base.ParamNameDef;
import com.lenovo.sdc.framework.cache.ACacheClient;
import com.lenovo.sdc.framework.cache.CacheFactory;
import com.lenovo.sdc.framework.util.AttributeBean;

/**
 * @author L
 *
 */
public class AppCache {
    private static ACacheClient cacheClient;

    /**
     * used for test we confige local mapdb as cache
     * in the feature, we will confige globle cache, use memcached or redis
     */
    public AppCache(AttributeBean attributes) {
        cacheClient = CacheFactory.getGlobalCache(attributes.getAttribute(ParamNameDef.CACHE_SERVER_NODE, "default"));
        
        /*String serverName = attributes.getAttribute(CACHE_SERVER_NAME, "app");
        int maxItems = attributes.getAttribute(CACHE_MAX_ITEMS, 50000);
        int maxTtl = attributes.getAttribute(CACHE_MAX_TTL, 86400);
        CacheServer server = new CacheServer(serverName, maxItems, maxTtl);
        String path = attributes.getAttribute(CACHE_FILE, System.getProperty("java.io.tmpdir"));
        if (path.endsWith("/") || path.endsWith("\\"))
            server.addAttribute("cacheFile", path + "mscache");
        else
            server.addAttribute("cacheFile", path + File.separatorChar + "mscache");
        String partition = attributes.getAttribute(CACHE_PARTITION, "appgateway");
        CacheNode cacheNode = new CacheNode(partition, CacheProvider.LSTP);
        cacheNode.addServers(server);

        cacheClient = CacheFactory.createCache(cacheNode);*/
    }

    public static ACacheClient getClient() {
        return cacheClient;
    }
}
